package com.qianli.cashmama.trade.repo.impl;

import com.qianli.cashmama.trade.dao.TBillExtensionRecordDao;
import com.qianli.cashmama.trade.domain.model.BillExtensionRecord;
import com.qianli.cashmama.trade.entity.TBillExtensionRecordEntity;
import com.qianli.cashmama.trade.repo.BillExtensionRecordRepository;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;


@Repository
public class BillExtensionRecordRepositoryImpl implements BillExtensionRecordRepository {

    @Autowired
    private TBillExtensionRecordDao tBillExtensionRecordDao;

    /**
     * 持久化保存
     */
    @Override
    public void store(BillExtensionRecord billExtensionRecord) {
        TBillExtensionRecordEntity entity = new TBillExtensionRecordEntity();
        BeanUtils.copyProperties(billExtensionRecord, entity);
        tBillExtensionRecordDao.insert(entity);
        billExtensionRecord.setId(entity.getId());
    }

    /**
     * 从数据库装载
     * @param id
     * @return
     */
    @Override
    public BillExtensionRecord load(long id) {
        TBillExtensionRecordEntity entity = tBillExtensionRecordDao.selectByPrimaryKey(id);
        if (entity == null) {
            return null;
        }
        BillExtensionRecord billExtensionRecord = new BillExtensionRecord();
        BeanUtils.copyProperties(entity, billExtensionRecord);
        return billExtensionRecord;
    }
}
